package com.fenda.jetpacknavigation;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavAction;
import androidx.navigation.NavController;
import androidx.navigation.NavHostController;
import androidx.navigation.Navigation;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.NavigationUI;

import android.content.Intent;
import android.os.Bundle;

import com.fenda.jetpacknavigation.inject.UserActivity;
import com.fenda.jetpacknavigation.roomdata.RoomActivity;

public class MainActivity extends AppCompatActivity {


    private NavController controller;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //标签为fragment
//        controller = Navigation.findNavController(this,R.id.fragmentContainerView);

        //标签为FragmentContainerView 或 fragment都可以
        controller = ( (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView)).getNavController();
        NavigationUI.setupActionBarWithNavController(this, controller);

        findViewById(R.id.button5).setOnClickListener( v -> startActivity(new Intent(this, UserActivity.class)));
        findViewById(R.id.button6).setOnClickListener( v -> startActivity(new Intent(this, RoomActivity.class)));
    }

    @Override
    public boolean onSupportNavigateUp() {
        return controller.navigateUp();
//        return super.onSupportNavigateUp();
    }
}